﻿using System;
using System.Linq;
using System.Text;
using VipCo.Data;
using VipCo.Entities;

public partial class Controls_BannerSliderControl : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            HienThiBannerSlider();
        }
    }

    public void HienThiBannerSlider()
    {
        // Lay ID cua nhom Quang cao : Banner SliderShow
        int totalRows = 0;
        TList<NhomQuangCao> tlistNqc =
            DataRepository.NhomQuangCaoProvider.GetPaged("Ten like N'" + Common.bannerSlide + "'", "Id", 0, 1,
                                                         out totalRows);
        int idNqc = 0;
        if (tlistNqc.Any())
        {
            idNqc = tlistNqc[0].Id;
        }

        // Lay danh sach cac quang cao thuoc Nhom quang cao nay
        TList<QuangCaoHome> tlistQch = DataRepository.QuangCaoHomeProvider.GetByIdQuangCao(idNqc);

        if (tlistQch.Any())
        {
            StringBuilder bannerSb = new StringBuilder();
            bannerSb.Append("<div id=\"slider\" class=\"nivoSlider\">");

            // Duyet quang cao home
            foreach (var quangCaoHome in tlistQch)
            {
                bannerSb.Append("<img src=\"" + "Upload/QuangCao/" + quangCaoHome.AnhDaiDien + "\" data-thumb=\"Images/1.jpg\" alt=\"\" />");
            }

            bannerSb.Append("</div>");

            litBanner.Text = bannerSb.ToString();
        }

        
    }
}